package com.unis.XmlNetty;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.unis.XmlNetty.beans.loaclConfig;
import com.unis.db.DBManager;

public class ConfigService {
	public static void insertOrUpdate(loaclConfig config) throws Exception{
		Object obj = new Object();
		String sql = "merge into utm_server_number" +"\r\t"+
				"using(select count(*) cnt from utm_server_number where c_bdjd = '"+config.getC_BDJD()+"' and c_ydjd = '"+config.getC_YDJD()+"' and c_cslx='"+config.getC_CSLX()+"') t1 " +"\r\t"+
				"on (t1.cnt>0) " +"\r\t"+
				"WHEN MATCHED THEN" +"\r\t"+
				"update set c_zdxh = '"+config.getC_ZDXH()+"',c_dqxh = '"+config.getC_DQXH()+"',c_sjlx = '"+config.getC_SJLX()+"',c_bz='"+config.getC_BZ()+"' ,c_bbh='"+config.getBBH()+"', d_xgsj=? where c_bdjd = '"+config.getC_BDJD()+"' and c_ydjd = '"+config.getC_YDJD()+"' and c_cslx='"+config.getC_CSLX()+"'\r\t"+
				"WHEN NOT MATCHED THEN" +"\r\t"+
				"insert(c_bdjd,c_cslx,c_ydjd,c_zdxh,c_dqxh,c_sjlx,d_xgsj,d_jlsj,c_bbh,c_bz) values('"+config.getC_BDJD()+"','"+config.getC_CSLX()+"','"+config.getC_YDJD()+"', '"+config.getC_ZDXH()+"','"+config.getC_DQXH()+"','"+config.getC_SJLX()+"',?,sysdate,'"+config.getBBH()+"','"+config.getC_BZ()+"')";
		Connection con = DBManager.getCon(obj);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setTimestamp(1, config.getD_XGSJ());
		ps.setTimestamp(2, config.getD_XGSJ());
		ps.execute();
		ps.close();
		DBManager.closeCon(obj);
	}
}
